package edu.ccut.titan.tag.chart.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;

/**
 * Created by IntelliJ IDEA.
 * User: Leslie
 * Date: 2005-11-17
 * Time: 10:00:03
 * Descriptions:
 *   当改对象在Session中无效时,删除图文件
 */
public class ServletChartDeleter implements HttpSessionBindingListener {
	
    private List<String> chartNames = new ArrayList<String>();

    public ServletChartDeleter() {
        super();
    }

    public void addChart(String realFileName) {
        this.chartNames.add(realFileName);
    }

    public boolean isChartAvailable(String filename) {
        return (this.chartNames.contains(filename));
    }

    public void valueBound(HttpSessionBindingEvent event) {
        return;
    }

    public void valueUnbound(HttpSessionBindingEvent event) {
    	for (String realFilename : this.chartNames) {
            File file = new File(realFilename);
            if (file.exists()) {
                file.delete();
            }
        }
        return;
    }
}
